home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / VideoFolderWindow.cp < prev    next >
Text File  |  1996-06-21  |  7KB  |  316 lines

  1. // ===========================================================================
  2. //    VideoFolderWindow.cp                   
  3. // ===========================================================================
  4.  
  5. #include "VideoFolderWindow.h"
  6.  
  7. #include "FSSpecPane.h"
  8. #include "MoreFilesExtras.h"
  9. #include "SequenceGrabberPane.h"
  10. #include "UStandardFile.h"
  11.  
  12. VideoFolderWindow* VideoFolderWindow::CreateVideoFolderWindowStream(LStream *inStream)
  13. {
  14.     return new VideoFolderWindow ( inStream );
  15. }
  16.  
  17. VideoFolderWindow::VideoFolderWindow( LStream *inStream) :
  18.     mDefaultOutline ( nil ),
  19.     LWindow ( inStream )
  20. {
  21. }
  22.  
  23. VideoFolderWindow::~VideoFolderWindow()
  24. {
  25.     delete mDefaultOutline;
  26. }
  27.  
  28. void VideoFolderWindow::DoGrab ( )
  29. {    
  30.     Try_ {
  31.         Rect frameRect;
  32.         mSequenceGrabberPane->CalcPortFrameRect ( frameRect );            
  33.         
  34.         LGWorld image ( frameRect, 8, useTempMem );
  35.  
  36.         mSequenceGrabberPane->Grab();
  37.         mSequenceGrabberPane->DrawSelf();
  38.  
  39.         image.BeginDrawing ();
  40.         mSequenceGrabberPane->DrawSelf();
  41.         image.EndDrawing();
  42.             
  43.         FSSpecPane* destFSSpecPane = dynamic_cast<FSSpecPane*> ( FindPaneByID ( 'DSTF' ) );
  44.         if ( destFSSpecPane )
  45.         {
  46.             FSSpec spec;
  47.             
  48.             destFSSpecPane->GetFSSpec ( spec );
  49.             
  50.             CFinderIconPicture iconMaker ( spec.vRefNum, spec.parID );
  51.             
  52.             iconMaker.AcceptPict ( image.GetMacGWorld() );
  53.         }
  54.     }
  55.     Catch_( inErr )
  56.     {
  57.     
  58.     }
  59. }
  60.  
  61. void VideoFolderWindow::DoSequenceGrabberSetup()
  62. {
  63.     mSequenceGrabberPane->DoSetupDialog();
  64.  
  65. }
  66.  
  67. void
  68. VideoFolderWindow::FindCommandStatus(
  69.     CommandT    inCommand,
  70.     Boolean        &outEnabled,
  71.     Boolean        &outUsesMark,
  72.     Char16        &outMark,
  73.     Str255        outName)
  74. {
  75.  
  76.     switch (inCommand)
  77.     {
  78.         // Return menu item status according to command messages.
  79.         // Any that you don't handle will be passed to LApplication
  80.  
  81.         case cmd_GrabFrame:                    // EXAMPLE
  82.             outEnabled = true;            // enable the New command
  83.             break;
  84.  
  85.         case cmd_GrabInterval:
  86.             outEnabled = true;
  87.             break;
  88.  
  89.         default:
  90.             LCommander::FindCommandStatus(inCommand, outEnabled,
  91.                                                 outUsesMark, outMark, outName);
  92.             break;
  93.     }
  94. }
  95.  
  96. void VideoFolderWindow::FinishCreate ( )
  97. {
  98.     LWindow::FinishCreate();
  99.  
  100.     mSequenceGrabberPane = dynamic_cast<SequenceGrabberPane*> ( FindPaneByID ( 'sgrb' ) );
  101.     ThrowIfNil_( mSequenceGrabberPane );
  102.  
  103.     LControl* grabButton = dynamic_cast<LControl*> ( FindPaneByID( 'GRAB' ) );
  104.     if (grabButton != nil)
  105.         mDefaultOutline = new LDefaultOutline(grabButton);
  106.     
  107.     UReanimator::LinkListenerToControls ( this, this, GetPaneID() );
  108.     StartListening();
  109.     StartIdling ();
  110.     
  111.     // mFinderIconPicture = nil;
  112.  
  113.     // mDestinationSpec.vRefNum = 0;
  114.     // mDestinationSpec.parID = 0;
  115.  
  116.     Boolean liveUpdate = true;
  117.     LPane* liveUpdateControl = dynamic_cast<LPane*> ( FindPaneByID ( 'LIVE' ) );
  118.     if ( liveUpdateControl )
  119.         liveUpdate = liveUpdateControl->GetValue() != 0;
  120.     mSequenceGrabberPane->SetLiveUpdate ( liveUpdate );
  121.     
  122.     unsigned long nextUpdateSecs;
  123.     GetDateTime ( & nextUpdateSecs );
  124.     nextUpdateSecs += 30;
  125.     
  126.     mNextUpdateControl = dynamic_cast<LPane*> ( FindPaneByID ( 'NEXT' ) );
  127.     if ( mNextUpdateControl )
  128.         mNextUpdateControl->SetValue ( nextUpdateSecs );
  129.         
  130.     mUpdateIntervalControl = dynamic_cast<LStdPopupMenu*> ( FindPaneByID ( 'INTV' ) );
  131. }
  132.  
  133. unsigned long intervals[] = { 60, 300, 15*60, 60*60, 4*60*60, 12*60*60, 24*60*60 };
  134.  
  135. unsigned long VideoFolderWindow::GetUpdateInterval ( ) const
  136. {    unsigned long result = 60 * 5;    //    default to every 5 minutes
  137.  
  138.     if ( mUpdateIntervalControl )
  139.     {    
  140.     
  141.         short value = mUpdateIntervalControl->GetValue();
  142.         
  143.         if ( 1 <= value && value <= sizeof( intervals ) )
  144.             result = intervals[ value - 1 ]; 
  145.     }
  146.  
  147.     return result;
  148. }
  149.  
  150. void VideoFolderWindow::SetUpdateInterval ( unsigned long interval )
  151. {
  152.     if ( mUpdateIntervalControl )
  153.     {    short value = 0;
  154.     
  155.         while ( value < sizeof( intervals ) && intervals[ value ] < interval )
  156.             value ++;
  157.  
  158.         mUpdateIntervalControl->SetValue( interval + 1 );
  159.     }
  160. }
  161.  
  162.  
  163. Boolean
  164. VideoFolderWindow::HandleKeyPress(
  165.     const EventRecord    &inKeyEvent)
  166. {
  167.     Boolean        keyHandled = false;
  168.     LControl    *keyButton = nil;
  169.     
  170.     switch (inKeyEvent.message & charCodeMask) {
  171.     
  172.         case char_Enter:
  173.         case char_Return:
  174.             keyButton = dynamic_cast<LControl*> ( FindPaneByID( 'GRAB' ) );
  175.             break;
  176.             
  177.         case char_Escape:
  178.             if ((inKeyEvent.message & keyCodeMask) == vkey_Escape) {
  179.                 keyButton =  dynamic_cast<LControl*> ( FindPaneByID( 2 ) );
  180.             }
  181.             break;
  182.  
  183.         default:
  184.             if (UKeyFilters::IsCmdPeriod(inKeyEvent)) {
  185.                 keyButton =  dynamic_cast<LControl*> ( FindPaneByID( 2 ) );
  186.             } else {
  187.                 keyHandled = LWindow::HandleKeyPress(inKeyEvent);
  188.             }
  189.             break;
  190.     }
  191.             
  192.     if (keyButton != nil) {
  193.         keyButton->SimulateHotSpotClick(kControlButtonPart);
  194.         keyHandled = true;
  195.     }
  196.     
  197.     return keyHandled;
  198. }
  199.  
  200. void VideoFolderWindow::ListenToMessage( MessageT        inMessage,
  201.                             void            *ioParam)
  202. {
  203.     switch ( inMessage )
  204.     {
  205.         case cmd_GrabFrame:
  206.             DoGrab ( );            
  207.             break;
  208.  
  209.         case cmd_SequenceGrabberSetup:
  210.             DoSequenceGrabberSetup();
  211.             break;    
  212.  
  213.         case cmd_LiveUpdateControl:
  214.             LPane* liveUpdate = dynamic_cast<LPane*> ( FindPaneByID ( 'LIVE' ) );
  215.             if ( liveUpdate )
  216.                 mSequenceGrabberPane->SetLiveUpdate ( liveUpdate->GetValue() != 0 );
  217.             break;
  218.         
  219.         case cmd_GrabInterval:
  220.             if ( mNextUpdateControl )
  221.             {    unsigned long now;
  222.                 GetDateTime ( & now );
  223.                 
  224.                 unsigned long nextUpdate = now + GetUpdateInterval();
  225.                 
  226.                 mNextUpdateControl->SetValue ( nextUpdate );
  227.             }
  228.             break;
  229.             
  230.         case cmd_SetDestination:
  231.             StandardFileReply reply;
  232.             
  233.             FSSpecPane* destFSSpecPane = dynamic_cast<FSSpecPane*> ( FindPaneByID ( 'DSTF' ) );
  234.             if ( destFSSpecPane )
  235.             {
  236.                 destFSSpecPane->GetFSSpec ( reply.sfFile );
  237.             
  238.                 if ( UStandardFile::GetDirectory ( reply ) )
  239.                 {
  240.                     reply.sfFile.name[0] = 0;
  241.                     destFSSpecPane->SetFSSpec ( reply.sfFile );
  242.                 }
  243.             }
  244.             break;
  245.     }
  246. }
  247.  
  248. Boolean VideoFolderWindow::ObeyCommand(
  249.                                 CommandT            inCommand,
  250.                                 void                *ioParam )
  251. {
  252.     Boolean        cmdHandled = true;
  253.  
  254.     switch (inCommand) {
  255.     
  256.         // Deal with command messages (defined in PP_Messages.h).
  257.         // Any that you don't handle will be passed to LApplication
  258.              
  259.         case cmd_GrabFrame:
  260.             DoGrab ();
  261.             break;
  262.  
  263.         case cmd_SequenceGrabberSetup:
  264.             DoSequenceGrabberSetup();
  265.             break;    
  266.  
  267.         case cmd_LiveUpdateControl:
  268.             LPane* liveUpdate = dynamic_cast<LPane*> ( FindPaneByID ( 'LIVE' ) );
  269.             if ( liveUpdate )
  270.                 mSequenceGrabberPane->SetLiveUpdate ( liveUpdate->GetValue() != 0 );
  271.             break;
  272.  
  273.         default:
  274.             cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
  275.             break;
  276.     }
  277.     
  278.     return cmdHandled;
  279. }
  280.  
  281. void VideoFolderWindow::SpendTime( const EventRecord        &inMacEvent)
  282. {
  283.     if ( mNextUpdateControl )
  284.     {    unsigned long now;
  285.     
  286.         GetDateTime ( & now );
  287.         
  288.         if ( mNextUpdateControl->GetValue() < now )
  289.         {
  290.             DoGrab ( );
  291.             mNextUpdateControl->SetValue ( now + GetUpdateInterval() );
  292.         }
  293.     }
  294.  
  295.  
  296. }
  297.  
  298. #if 0
  299. void VideoFolderWindow::GetDestination ( FSSpec& outSpec )
  300. {
  301.     outSpec = mDestinationSpec;
  302. }
  303.  
  304. void VideoFolderWindow::SetDestination ( const FSSpec& inSpec )
  305. {
  306.     // delete mFinderIconPicture;
  307.     // mFinderIconPicture = nil;
  308.  
  309.     mDestinationSpec = inSpec;
  310.  
  311.     long dirID;
  312.     Boolean isDirectory;
  313.     if ( GetDirectoryID( mDestinationSpec.vRefNum, mDestinationSpec.parID, (StringPtr) "\p", & dirID, & isDirectory ) == noErr )
  314.         mFinderIconPicture = new CFinderIconPicture ( mDestinationSpec.vRefNum, dirID );
  315. }
  316. #endif